#set(tableComment = table.getComment())
#set(entityClassName = table.buildEntityClassName())
#set(entityVarName = firstCharToLowerCase(entityClassName))
#set(serviceVarName = firstCharToLowerCase(table.buildServiceClassName()))
#set(mapperName = firstCharToLowerCase(table.buildMapperClassName()))
package #(packageConfig.controllerPackage);

import abg.core.common.util.StringKit;
import #(packageConfig.entityPackage).#(entityClassName);
import #(packageConfig.servicePackage).#(table.buildServiceClassName());
import abg.core.domain.search.Psh;
import #(packageConfig.mapperPackage).#(table.buildMapperClassName());
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * #(table.getComment()) 服务层实现。
 *
 * @author #(javadocConfig.getAuthor())
 * @since #(javadocConfig.getSince())
 */
@Service
#if(isCacheExample)
@CacheConfig(cacheNames = "#(firstCharToLowerCase(entityClassName))")
#end
public class #(table.buildServiceImplClassName()) implements #(table.buildServiceClassName()) {

    @Resource
    private #(table.buildMapperClassName()) #(mapperName);

    /**
     * 插入数据#(tableComment)
     */
    @Override
    public boolean insert(#(entityClassName) #(entityVarName)) {
        //检查重复
        //        QueryWrapper eq = QueryWrapper.create().eq("name", "test");
        //        AaBm aaBm = aaBmMapper.selectOneByQuery(eq);
        //        if (aaBm != null) throw new SrsException(MSG.NAME_EXISTS);
        //        #(entityVarName).setId(null);
        #(mapperName).insertSelective(#(entityVarName));
        return true;
    }

    /**
     * 根据主键删除#(tableComment)
     *
     * @param ids 逗号分隔字符串
     */
    @Override
    public boolean delete(String ids) {
        ArrayList<String> idList = StringKit.split(ids);
        #(mapperName).deleteBatchByIds(idList);
        return true;
    }

    /**
     * 根据主键更新#(tableComment)
     */
    @Override
    public boolean update(#(entityClassName) #(entityVarName)) {
        #(mapperName).update(#(entityVarName));
        return true;
    }

    /**
     * 根据#(tableComment)主键获取详细信息。
     */
    @Override
    public #(entityClassName) info(String id) {
        return #(mapperName).selectOneById(id);
    }

    /**
     * 分页查询#(tableComment)
     *
     * @param #(entityVarName) 搜索条件
     * @param psh 搜索条件
     */
    @Override
    public Page<#(entityClassName)> page(#(entityClassName) #(entityVarName), Psh psh) {
        QueryWrapper wrapper = QueryWrapper.create();
        //        QueryWrapper wrapper = QueryWrapper.create()
        //                .and(SYS_MSG.MSG_TYPE_ID.eq(param.getName()))
        //                .and(SYS_MSG.TITLE.like(param.getCode()))
        //                .orderBy(SYS_MSG.CT.desc());
        return #(mapperName).paginate(psh, wrapper);
    }

}
